package com.leapp.sk.viewdelegate.notify

import android.content.Context
import android.support.v7.app.AppCompatActivity
import android.text.TextUtils
import android.view.View
import android.widget.RelativeLayout
import android.widget.TextView
import com.example.baselibrary.util.LKToastUtil
import com.example.mvp.delegate.BaseAppDelegate
import com.example.mvp.view.ContainsEmojiEditText
import com.example.mvp.view.NoScrollGridView
import com.example.mvp.view.SKTopBar
import com.leapp.sk.R
import com.leapp.sk.ui.activity.notify.SendNotifyActivity
import com.leapp.sk.ui.adapter.SendNotifyUPImageAdapter

/**
 * 发送通知
 * @author  chaohaipeng  on 2018/8/10.
 */
class SendNotifyDelegate :BaseAppDelegate() {
    /**
     * 刷新适配器
     */
    var sendNotifyUPImageAdapter:SendNotifyUPImageAdapter?=null

    override fun initWidget() {
    }

    override fun initLayoutRes(): Int {
        return R.layout.activity_send_notify
    }

    /**
     * 初始化适配器
     */
   fun initAdapter(context: Context, mlist: MutableList<String>){
        val gv_asn_up_image = getView<NoScrollGridView>(R.id.gv_asn_up_image)
        sendNotifyUPImageAdapter = SendNotifyUPImageAdapter(context, mlist)
        gv_asn_up_image.adapter=sendNotifyUPImageAdapter

    }
    /**
     * 刷新适配器
     */
    fun notifyIvAdapter(){
        sendNotifyUPImageAdapter?.notifyDataSetChanged()
    }

    /**
     * 获取标题
     */
    fun getTitle():String{
        val et_asn_title = getView<ContainsEmojiEditText>(R.id.et_asn_title)
        val trim = et_asn_title.text.toString().trim()
        if (TextUtils.isEmpty(trim)){
            LKToastUtil.showToastShort(getActivity<AppCompatActivity>().resources.getString(R.string.string_notify_input_title))
        }
        return trim
    }
    /**
     * 获取内容
     */
    fun getContent():String{
        val et_asn_notify_content = getView<ContainsEmojiEditText>(R.id.et_asn_notify_content)
        val trim = et_asn_notify_content.text.toString().trim()
        if (TextUtils.isEmpty(trim)){
            LKToastUtil.showToastShort(getActivity<AppCompatActivity>().resources.getString(R.string.string_notify_input_content))
        }
        return trim
    }
    /**
     * 设置班级
     */
    fun setClass(classS:String?){
        if (!TextUtils.isEmpty(classS)){
            val rl_asn_class_data = getView<RelativeLayout>(R.id.rl_asn_class_data)
            rl_asn_class_data.visibility= View.VISIBLE
            val tv_asn_class_data = getView<TextView>(R.id.tv_asn_class_data)
            tv_asn_class_data.text=classS
        }

    }


    /**
     * 设置标题
     */
    fun setTitle(title:String?){
        val jtb_asn_send= getView<SKTopBar>(R.id.jtb_asn_send)
        if (!TextUtils.isEmpty(title)){
            jtb_asn_send?.setTitle(title)
        }
        setEvent(jtb_asn_send)
    }
    /**
     * 设置设置事件
     */
    private  fun setEvent(topBar:SKTopBar){
        topBar?.setEventInterface(object : SKTopBar.EventInterface{
            override fun leftOnClick() {
                getActivity<SendNotifyActivity>().finish()
            }
            override fun rightOnClick() {
            }

        })
    }

}